# @Time    : 2019/8/2 15:44
# @Author  : patrick
# @File    : assembleJson.py
# @Software: PyCharm


class AssembleJson:
    def person_json(self, **kwargs):
        """
        个险参数JSON
        :param kwargs: 动态参数
        :return: 个险JSON
        """
        print("年龄：%s，ProductCode：%s, Coverage：%s" % (kwargs.get("age"), kwargs.get("salesProductCode"), kwargs.get("coverage")))
        person_json = {
            # 客户ID
            "customerId": "bcdbaab31aff4ec9b748262e23cdf0c6",
            # 客户类型 主被保人 / 次被保人
            "customerType": None,
            # 生效日期
            "effectiveDate": None,
            # 保费计算日期
            "settlementDate": None,
            "plans": self.person_plans(
                salesProductCode=kwargs.get("salesProductCode"),
                coverage=kwargs.get("coverage"),
                paymentPeriod=kwargs.get("paymentPeriod"),
                hasSecurity=kwargs.get("hasSecurity"),
                sex=kwargs.get("sex"),
                age=kwargs.get("age"),
                paymentMethod=kwargs.get("paymentMethod"),
                occupationCode=kwargs.get("occupationCode")),
            # 期缴总加费
            "regularCustAddPremium": None,
            # 客户总加费
            "custAddPremium": None,
            # 客户总保费（应缴保费）
            "customerPremium": None,
            # 年化保费
            "annualPremium": None,
            # 期缴基础保费
            "regularBasicPremium": None,
            # 期缴加费保费
            "regularAddPremium": None,
            # 期缴保费
            "regularPremium": None
        }
        return person_json

    def person_plans(self, **kwargs):
        """
        个险计划JSON列表，无附加险时只有一个，此列表随主险与附加险变化
        :param kwargs: 动态参数
        :return: 完整的个险计划JSON列表
        """
        plans = []
        # 分割多个产品号与保额
        productCodes = kwargs.get("salesProductCode").split(",")
        coverage = kwargs.get("coverage").split(",")
        if productCodes.__len__() > 1:
            for i in range(0, productCodes.__len__()):
                plansJson = self.plans_json(
                    salesProductCode=productCodes[i].strip(),
                    coverage=coverage[i].strip(),
                    paymentPeriod=kwargs.get("paymentPeriod"),
                    hasSecurity=kwargs.get("hasSecurity"),
                    sex=kwargs.get("sex"),
                    age=kwargs.get("age"),
                    paymentMethod=kwargs.get("paymentMethod"),
                    occupationCode=kwargs.get("occupationCode")
                )
                plans.append(plansJson)
        else:
            plansJson = self.plans_json(
                salesProductCode=productCodes[0],
                coverage=coverage[0],
                paymentPeriod=kwargs.get("paymentPeriod"),
                hasSecurity=kwargs.get("hasSecurity"),
                sex=kwargs.get("sex"),
                age=kwargs.get("age"),
                paymentMethod=kwargs.get("paymentMethod"),
                occupationCode=kwargs.get("occupationCode")
            )
            plans.append(plansJson)
        return plans

    def plans_json(self, **kwargs):
        """
        个险计划JSON
        :param kwargs: 动态参数
        :return: 个险计划JSON
        """
        # paymentPeriodUnit = ""  缴费年限单位 Y-年；A-岁,"MI03" or "MI04"单位为 A
        if kwargs.get("salesProductCode") == "MI03" or kwargs.get("salesProductCode") == "MI04":
            paymentPeriodUnit = "A"
        else:
            paymentPeriodUnit = "Y"
        # print(paymentPeriodUnit)

        plans_json = {
                # 是否可被豁免字段
                "isExemptions": "1",
                # 产品代码
                "salesProductCode": kwargs.get("salesProductCode") if kwargs.get("salesProductCode") is not None else "PDLW06",
                # 保额
                "coverage": kwargs.get("coverage") if kwargs.get("coverage") is not None else "50000",
                # 保单量(份数)
                "policyNum": None,
                # 产品年化保费
                "annualPremium": None,
                # 保费
                "premium": None,
                # 职业期缴加费
                "regularOccupationPremiumAdd": None,
                # 职业加费 1-千元加费；2-比例
                "occupationPremiumAdd": None,
                # 健康加费 1-千元加费；2-比例
                "healthyPremiumAdd": None,
                # 计划期缴健康加费
                "regularHealthyPremiumAdd": None,
                # 计划总保费
                "planPremium": None,
                # 健康费率类型
                "healthyType": None,
                # 健康费率
                "healthyRate": None,
                # 职业费率类型
                "occupationType": None,
                # 保障年限
                "protectionPeriod": "106",
                # 保单年度 首期保费为1
                "policyYear": "1",
                # 缴费年限 5,10,15,20
                "paymentPeriod": kwargs.get("paymentPeriod") if kwargs.get("paymentPeriod") is not None else "5",
                # 缴费年限单位 Y-年；A-岁；不传值则默认按照Y处理,区分大小写
                "paymentPeriodUnit": paymentPeriodUnit,
                # 有无社保 Y-有社保；N-无社保
                "hasSecurity": kwargs.get("hasSecurity") if kwargs.get("hasSecurity") is not None else "Y",
                # 高中低（分红利率）
                "level": None,
                # 性别
                "sex": kwargs.get("sex") if kwargs.get("sex") is not None else "M",
                # 生日，生日、年龄字段只需赋值一个即可
                # "birthday": "1987-03-07",
                # 年龄，生日、年龄字段只需赋值一个即可
                "age": kwargs.get("age") if kwargs.get("age") is not None else "34",
                # 缴费方式 00：趸交，01：年缴，02：半年缴，04:季缴，12：月缴
                "paymentMethod": kwargs.get("paymentMethod") if kwargs.get("paymentMethod") is not None else "01",
                # 职业费率
                "occupationRate": None,
                # 加费额度，默认值：1000
                "increaseKey": None,
                # 加费方式
                "increaseWay": None,
                # 加费值
                "increaseValue": None,
                # 千元加费年化保费
                "increaseAnnualPremium": None,
                # 千元加费保费
                "increasePremium": None,
                # 健康K值
                "healthy": None,
                # 职业代码
                "occupationCode": kwargs.get("occupationCode") if kwargs.get("occupationCode") is not None else "0007",
                # 被豁免的险种，PB情况再传
                "salesProductCodeExemptions": None,
                # 期缴保费（险种层）
                "payablePremium": None,
                # 期缴基础保费
                "payableBasicPremium": None,
                # 期缴加费保费
                "payableAddPremium": None,
                # 期缴加费保费集合
                "payableAddPremiumList": None
            }
        return plans_json


if __name__ == '__main__':
    aJson = AssembleJson()
    print(aJson.person_plans(salesProductCode="PDLW06, LWA2, MMA7", age="35"))
